package com.jiugang.cardump.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jiugang.cardump.entity.Equipment;
import com.jiugang.cardump.entity.ProEquRef;
import com.jiugang.cardump.mapper.EquipmentMapper;
import com.jiugang.cardump.mapper.ProEquRefMapper;
import com.jiugang.cardump.result.ResultInfoV110;
import com.jiugang.cardump.service.ProEquRefService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2021-08-19
 */
@Service
public class ProEquRefServiceImpl extends ServiceImpl<ProEquRefMapper, ProEquRef> implements ProEquRefService {

    @Autowired
    ProEquRefMapper proEquRefMapper;
    @Autowired
    EquipmentMapper equipmentMapper;

    /**
     * @Author luoxin
     * @Description 根据id查询设备信息
     * @Date 3:31 下午 2021/8/20
     * @param proId
     * @return
     */
    @Override
    public ResultInfoV110 selectEqu(Integer proId) {
        log.debug("ProEquRefServiceImpl的selectEqu方法进入，参数为"+proId);
        QueryWrapper<ProEquRef> proEquRefQueryWrapper = new QueryWrapper<>();
        proEquRefQueryWrapper.eq("pro_id",proId);
        List<ProEquRef> proEquRefs = proEquRefMapper.selectList(proEquRefQueryWrapper);
        List<Equipment> equList = new ArrayList();
        for(ProEquRef ProEquRef:proEquRefs){
            QueryWrapper<Equipment> equipmentQueryWrapper = new QueryWrapper<>();
            Integer equTableId = ProEquRef.getEquTableId();
            equipmentQueryWrapper.eq("table_id",equTableId);
            Equipment selectEquipment = equipmentMapper.selectOne(equipmentQueryWrapper);
            equList.add(selectEquipment);
        }
        log.debug("ProEquRefServiceImpl的selectEqu方法结束");
        return ResultInfoV110.success(equList);
    }
}
